import docx

name = '张三' #被邀请者的名字
template = 'template.docx'  #模板的文件名
name_placeholder = "<name>" #要被替换的字符，也成为占位符
doc = docx.Document(template)

#循环每个段落
for para in doc.paragraphs:
    if name_placeholder in para.text:
        #循环段落中的每一组文字
        for run in para.runs:
            if name_placeholder in run.text:
                #用具体名字替换占位符
                run.text = run.text.replace(name_placeholder, name)

doc.save(f'{name}.docx')
